class Student {
  fullName: string;
  constructor(public firstName, public middleInitial, public lastName) {
    this.fullName = firstName + " " + middleInitial + " " + lastName;
  }
}
interface Person {
  firstName: string;
  lastName: string;
}

function greeter(person: Person) {
  return "Hello, " + person.firstName + " " + person.lastName;
}
let use = new Student("Tery", "Tao", "Tang");
document.body.innerHTML = greeter(use);

let list: number[] = [1, 2, 3];
let list2: Array<number> = [4, 5, 6];
console.log(list, list2);

let x: [string, number];
x = ["2", 2];
console.log(x);
console.log(x[0].substr);

enum Color {
  Red = 1,
  Green = 2,
  Blue = 4,
}
let colorName: string = Color[2];
console.log(colorName);

let notSure: any = 3;
notSure = "Maybe a string instead";
notSure = false;
let list3: any[] = [1, true, "free"];
list3[2] = 100;
console.log(list3);

function warnUser(): void {
  console.log("This is my warning message");
}

let unusable: void = undefined;

let someValue: any = "this is a string";

let strLength: number = (<string>someValue).length;
let strLength2: number = (someValue as string).length;

console.log(strLength2);

function f(shouldInitialize: boolean) {
  if (shouldInitialize) {
    var x = 10;
  }
  return x;
}

console.log(f(true), f(false));

// for (var i = 0; i < 10; i++) {
//   // capture the current state of 'i'
//   // by invoking a function with its current value
//   (function(k) {
//     setTimeout(function() { console.log(k); }, 100 * i);
//   })(i);
// }
// for (let i = 0; i < 10 ; i++) {
//   setTimeout(function() {console.log(i); }, 100 * i);
// }
function theCityThatAlwaysSleeps() {
  let getCity;

  if (true) {
    let city = "Seattle";
    getCity = function () {
      return city;
    };
  }

  return getCity();
}

console.log(theCityThatAlwaysSleeps());

function f2([first, second]: [number, number]) {
  console.log(first);
  console.log(second);
}
let [first, ...rest] = [5, 6, 7];
const ipt: [number, number] = [1, 3];
const ipt2: [any, number] = [2, 4];
f2(rest);

let o = {
  a: "foo",
  b: 12,
  c: "bar",
};

let { a, b }: { a: string; b: number } = o;
function keepWholeObject(wholeObject: { a: string; b?: number }) {
  let { a, b = 1001 } = wholeObject;
}
